﻿@{
    //page title
    ViewBag.Title = T("Admin.System.ScheduleTasks").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.System.ScheduleTasks")
    </div>
</div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#schedule-tasks-grid").on("click", ".run-now", function (e) {
                showThrobber('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.System.ScheduleTasks.RunNow.Progress").Text))');
            });
        });
    </script>    
<table class="adminContent">
    <tr>
        <td>
            <strong>@T("Admin.System.ScheduleTasks.RestartApplication")</strong>
        </td>
    </tr>
    <tr>
        <td>
            <div id="schedule-tasks-grid"></div>

            <script>
                $(document).ready(function () {
                    $("#schedule-tasks-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("List", "ScheduleTask"))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                update: {
                                    url:"@Html.Raw(Url.Action("TaskUpdate", "ScheduleTask"))",
                                    type: "POST",
                                    dataType: "json"
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                    fields: {
                                        Name: { editable: true, type: "string" },
                                        Seconds: { editable: true, type: "number" },
                                        Enabled: { editable: true, type: "boolean" },
                                        StopOnError: { editable: true, type: "boolean" },
                                        LastStartUtc: { editable: false, type: "date" },
                                        LastEndUtc: { editable: false, type: "date" },
                                        LastSuccessUtc: { editable: false, type: "date" },
                                        Id: { editable: false, type: "number" }
                                    }
                                }
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info: false
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "Name",
                            title: "@T("Admin.System.ScheduleTasks.Name")",
                            width: 300
                        }, {
                            field: "Seconds",
                            title: "@T("Admin.System.ScheduleTasks.Seconds")",
                            width: 50
                        }, {
                            field: "Enabled",
                            title: "@T("Admin.System.ScheduleTasks.Enabled")",
                            width: 100,
                            headerAttributes: { style: "text-align:center" },
                            attributes: { style: "text-align:center" },
                            template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=Enabled#.gif" />'
                        }, {
                            field: "StopOnError",
                            title: "@T("Admin.System.ScheduleTasks.StopOnError")",
                            width: 100,
                            headerAttributes: { style: "text-align:center" },
                            attributes: { style: "text-align:center" },
                            template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=StopOnError#.gif" />'
                        }, {
                            field: "LastStartUtc",
                            title: "@T("Admin.System.ScheduleTasks.LastStart")",
                            width: 200,
                            type: "date",
                            format: "{0:G}"
                        }, {
                            field: "LastEndUtc",
                            title: "@T("Admin.System.ScheduleTasks.LastEnd")",
                            width: 200,
                            type: "date",
                            format: "{0:G}"
                        }, {
                            field: "LastSuccessUtc",
                            title: "@T("Admin.System.ScheduleTasks.LastSuccess")",
                            width: 200,
                            type: "date",
                            format: "{0:G}"
                        }, {
                            field: "Id",
                            title: "@T("Admin.System.ScheduleTasks.RunNow")",
                            width: 100,
                            template: '<a href="@Url.Content("~/Admin/ScheduleTask/RunNow/")#=Id#" class="k-button run-now">@T("Admin.System.ScheduleTasks.RunNow")</a>'
                        }, {
                            command: { name: "edit", text: "@T("Admin.Common.Edit")" },
                            title: "@T("Admin.Common.Edit")",
                            width: 100
                        }]
                    });
                });
            </script>
        </td>
    </tr>
</table>
